package com.wyj.permissions

import android.Manifest
import com.hjq.permissions.Permission
import com.wyj.utils.SdkVersionUtils

class PermissionsBuilder {
    private val permissionArray = ArrayList<String>()

    companion object {
        fun create(): PermissionsBuilder {
            return PermissionsBuilder()
        }
    }

    fun addOtherPermissions(vararg permission: String): PermissionsBuilder {
        permissionArray.addAll(permission)
        return this
    }

    fun addLocationPermissions(): PermissionsBuilder {
        permissionArray.add(Permission.ACCESS_FINE_LOCATION)
        permissionArray.add(Permission.ACCESS_COARSE_LOCATION)
        return this
    }

    fun addMicroPhonePermissions(): PermissionsBuilder {
        permissionArray.add(Permission.RECORD_AUDIO)
        return this
    }

    fun addNotificationPermissions(): PermissionsBuilder {
        permissionArray.add(Permission.NOTIFICATION_SERVICE)
        return this
    }

    fun addCameraPermissions(): PermissionsBuilder {
        permissionArray.add(Permission.CAMERA)
        return this
    }

    fun addWifiStatePermissions(): PermissionsBuilder {
        permissionArray.add(Manifest.permission.ACCESS_WIFI_STATE)
        permissionArray.add(Manifest.permission.CHANGE_WIFI_STATE)
        return this
    }

    fun addExternalStoragePermissions(): PermissionsBuilder {
        permissionArray.add(Permission.MANAGE_EXTERNAL_STORAGE)
        return this
    }

    fun add(permission: String): PermissionsBuilder {
        permissionArray.add(permission)
        return this;
    }

    fun builder(): Array<String> {
        val array = arrayOfNulls<String>(permissionArray.size)
        permissionArray.toArray(array)
        return array.filterNotNull().toTypedArray()
    }
}